﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using System.Windows.Threading;
using SimpleMvvmToolkit;

namespace SpotTheMisspell.CustomNavigator
{
    public class CustomNavigation : Navigator
    {
        Dispatcher currentDispatcher;
        public CustomNavigation(Dispatcher d)
        {
            currentDispatcher = d;
        }
        private Stack<Uri> _navQue = new Stack<Uri>();

        public void Navigate(string pageName)
        {
            var frame = (PhoneApplicationFrame)Application.Current.RootVisual;

            Uri pageUri = new Uri("/Views/" + pageName + ".xaml", UriKind.Relative);
            frame.Navigate(pageUri);
            // skip the game page
            if (!frame.CurrentSource.ToString().Contains("GamePage"))
            {
                _navQue.Push(frame.CurrentSource);

            }

          

        }
        public void Back()
        {
            currentDispatcher.BeginInvoke(() =>
            {
                var frame = (PhoneApplicationFrame)Application.Current.RootVisual;
                var b = _navQue.Pop();
                frame.Navigate(b);

            });

        }
    }
}
